Back in black#
\[
\newcommand{\eg}{{\it e.g.}}
\newcommand{\ie}{{\it i.e.}}
\newcommand{\argmin}{\operatornamewithlimits{argmin}}
\newcommand{\mc}{\mathcal}
\newcommand{\mb}{\mathbb}
\newcommand{\mf}{\mathbf}
\newcommand{\minimize}{{\text{minimize}}}
\newcommand{\diag}{{\text{diag}}}
\newcommand{\cond}{{\text{cond}}}
\newcommand{\rank}{{\text{rank }}}
\newcommand{\range}{{\mathcal{R}}}
\newcommand{\null}{{\mathcal{N}}}
\newcommand{\tr}{{\text{trace}}}
\newcommand{\dom}{{\text{dom}}}
\newcommand{\dist}{{\text{dist}}}
\newcommand{\R}{\mathbf{R}}
\newcommand{\C}{\mathbf{C}}
\newcommand{\SM}{\mathbf{S}}
\newcommand{\ball}{\mathcal{B}}
\newcommand{\bmat}[1]{\begin{bmatrix}#1\end{bmatrix}}
\]
ASE3001: Computational Experiments for Aerospace Engineering, Inha University.
Jong-Han Kim (jonghank@inha.ac.kr)
사운드 샘플(
.wav
파일)을 로드한다음원이 어떤 음표(또는 코드)로 구성되어 있는지 확인한다.
: 주파수-음표 매칭 표는 구글 검색 등을 통해 찾을 수 있다.
https://en.wikipedia.org/wiki/Piano_key_frequencies
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
from IPython.display import Audio
wav file을 불러온다.
시간에 따른 음성 신호를 도시하고 sound clip을 재생한다.
불러온 데이터는
data[0]
: samplling rate과data[1]
: time-series signal로 구성된다.requests 모듈이 import 되지 않는다면 셀에서 다음을 실행한다.
! pip install requests
import requests
#URL로 부터 파일 받기 from https://jonghank.github.io/ase3001/files/back_in_black.wav
response = requests.get('https://jonghank.github.io/ase3001/files/back_in_black.wav')
local_file_path = './test.wav'
if response.status_code == 200:
with open(local_file_path, 'wb') as file:
file.write(response.content)
print("Download success")
else:
print("Download fail")
data = wavfile.read('./test.wav')
framerate = data[0]
sounddata = data[1]
t = np.arange(0,len(sounddata))/framerate
plt.figure(figsize=(12,4), dpi=100)
plt.plot(t,sounddata[:,0], label='Right channel')
plt.plot(t,sounddata[:,1], label='Left channel')
plt.xlabel(r'$t$')
plt.title('Stereo signal')
plt.legend()
plt.show()
Audio([sounddata[:,1], sounddata[:,0]], rate=framerate, autoplay=True)
Download success
